﻿<%@ Page Title="Users" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" 
	Inherits="System.Web.Mvc.ViewPage<MindMelder.Core.User>" %>
<%@ Import Namespace="MindMelder.Core" %>
<%@ Import Namespace="MindMelder.Web.Controllers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
	<script src="~/../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>  
  
	<script type="text/javascript">  
	  
		function deleteRecord(userId, skillName)  
		{  
			// Perform delete
			var action = "/Users/RemoveSkill?Id=" + userId + "&skillName=" + skillName;
	              
			var request = new Sys.Net.WebRequest();  
			request.set_httpVerb("DELETE");  
			request.set_url(action);  
			request.add_completed(deleteCompleted);  
			request.invoke();  
		}  
	  
		function deleteCompleted()  
		{  
			// Reload page
			window.location.reload();  
		}  
	  
	</script>  
    <h2><%=ViewContext.TempData["heading"]%></h2>

    <%
    	if (ViewContext.TempData["message"] != null)
    	{%>
        <p><%=ViewContext.TempData["message"]%></p>
    <%
    	}%>
	<%=Html.ActionLink<UsersController>(c => c.Show(ViewData.Model.Id),
	                                                   ViewContext.TempData["backlink"].ToString())%>
	<br />
	<br />
	<% if (Model.Skills.Count > 0) { %>
    <table>
		<%
		foreach (Skill skill in ViewData.Model.Skills) {%>
			<tr>
				<td>
					<%=Html.ActionLink<UsersController>(
								c => c.ShowUsersWithSkill(skill.Name), skill.Name, new { title = skill.Description })%>
    		        <% if (ViewContext.TempData["loggedonuser"] != null && ViewContext.TempData["loggedonuser"].ToString() == "true") { %>
    					<input type="button" onclick="deleteRecord(<%=ViewData.Model.Id%>, '<%= Url.Encode(skill.Name) %>')" value="X" title="Remove this skill" />
    		        <% } %>
				</td>
			</tr>
		<%
		}%>
    </table>
    <% }
	else { %>
	<p><%= Model.FullName %> hasn't added any skills yet.</p>
	<% }%>
    
    
    <% if (ViewContext.TempData["loggedonuser"].ToString() == "true") { %>
		<h3>Add a skill</h3>
		<%= Html.ValidationSummary() %>
	<%
    	if (ViewContext.TempData["skillmessage"] != null)
    	{%>
        <p><%=ViewContext.TempData["skillmessage"]%></p>
    <%
    	}%>
		<% using (Html.BeginForm()) { %>
			<%= Html.AntiForgeryToken() %>
			<ul>
				<li>
					<label for="Skill.Name">Skill name:</label>
					<div>
						<%= Html.TextBox("Skill.Name", "")%>
					</div>
					<%= Html.ValidationMessage("Skill.FirstName")%>
				</li>
				<li>
					<label for="Skill.Description">Description:</label>
					<div>
						<%= Html.TextBox("Skill.Description", "")%>
					</div>
					<%= Html.ValidationMessage("Skill.Description")%>
				</li>
				<li>
					<%= Html.SubmitButton("btnSave", "Add Skill") %>
				</li>
			</ul>
			<% } %>
    <% } %>
    
</asp:Content>